from flask import Blueprint,request,make_response,jsonify,redirect,json
import requests
import random
from application.models.users.user import *
from application.models.users.user import db
# from db import db
import time
from utils.Myjwt import myjwt
gou_blue = Blueprint("gouwu",__name__)
@gou_blue.route('/tianjia',methods=['POST'])
def tianjia():
    data = json.loads(request.data)
    uid = data['uid']
    kid = data['kid']
    shu = data['count']
    is_check  = 20* int(shu)
    c = Cart(userid=uid,cid=kid,count=shu,is_check=is_check)
    db.session.add(c)
    db.session.commit()
    return jsonify({'code':200,'msg':'加入购物车成功'})
@gou_blue.route('/gouwuzhan')
def gouwuzhan():
    uid = request.args.get('userid')
    o = Course.query.filter_by(id=uid).all()
    list = []
    for i in o:
        list.append({
            'id': i.id,
            'name': i.name,
            'descrip': i.descrip,
        })
    return jsonify({'code':200,'data':list})
